package 测试;

public class 左右最值最大差 {

	public static void main(String[] args) {
		int[] a = new int[] { 28, 75, 38, 44, 66, 1 };
		System.out.println(new MaxGap().findMaxGap(a, a.length));
	}

	public static class MaxGap {
		public int findMaxGap(int[] A, int n) {
			int lmax = 0, rmax = 0, max = 0;
			for (int idx = 0; idx < n - 1; idx++) {
				for (int i = 0; i <= idx; i++) {
					lmax = Math.max(A[i], lmax);
				}
				for (int i = idx + 1; i < n; i++) {
					rmax = Math.max(A[i], rmax);
				}
				max = Math.max(Math.abs(lmax - rmax), max);
				lmax = rmax = 0;
			}
			return max;
		}
	}
}
